package com.cn.mmd.controller;

import com.cn.mmd.model.*;
import com.cn.mmd.service.*;
import com.cn.mmd.tools.AliyunOssUtil;
import com.cn.mmd.tools.SplitSpring;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 作业
 */
@Controller
@RequestMapping(value = "page/work")
public class WorkController {

    @Autowired
    private WorkService workService;

    @Autowired
    private CourseService courseService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private StudentGroupingService studentGroupingService;

    @Autowired
    private StudentAppService studentAppService;

    SplitSpring splitSpring = new SplitSpring();

    @Autowired
    private TokenController tokenController;

    /**
     * 查看作业
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/select")
    public synchronized
    @ResponseBody
    Object teacherSelectWork(HttpServletRequest request) {
        Map<String, Object> objectMap = new HashMap<String, Object>();
        List<Map> mapList = new ArrayList<Map>();
        Map<String, Object> map;
        String workName = request.getParameter("workName");
        String taecherId = request.getParameter("teacherId");
        int startrow = Integer.parseInt(request.getParameter("startrow"));
        int pageSize = Integer.parseInt(request.getParameter("pageSize"));
        String token = request.getParameter("token");
        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(taecherId, token);
        if (teacherData != null) {
            if (startrow < 1) {
                startrow = 1;
            }
            startrow = (startrow - 1) * pageSize;
            Schoolwork schoolwork1 = new Schoolwork(workName, startrow, pageSize, taecherId);
            List<Schoolwork> schoolwork = workService.selectAll(schoolwork1);
            StudentWork studentWork;
            Schoolwork schoolwork2 = new Schoolwork();
            schoolwork2.setWorkname(taecherId);
            if (schoolwork != null) {
                if (schoolwork.size() > 0) {
                    for (int i = 0; i < schoolwork.size(); i++) {
                        int num = 0;
                        map = new HashMap<String, Object>();
                        map.put("schoolWorkId", schoolwork.get(i).getSchoolworkid() + "");
                        map.put("workName", schoolwork.get(i).getWorkname());
                        map.put("releaseTime", schoolwork.get(i).getReleasetime());
                        map.put("handoverTime", schoolwork.get(i).getHandovertime());
                        map.put("schoolWorkContent", schoolwork.get(i).getSchoolworkcontent());
                        map.put("courseId", schoolwork.get(i).getCourseskuid());
                        studentWork = new StudentWork();
                        studentWork.setWorkid(schoolwork.get(i).getSchoolworkid());
                        studentWork.setWorktype("已阅读");
                        num = workService.selectByCount(studentWork);
                        map.put("readNum", num + "");
                        mapList.add(map);
                    }
                    objectMap.put("total", workService.countLimitNum(schoolwork2));
                    objectMap.put("code", 200);
                    objectMap.put("message", "成功");
                    objectMap.put("data", mapList);
                } else {
                    objectMap.put("total", workService.countLimitNum(schoolwork2));
                    objectMap.put("code", 201);
                    objectMap.put("message", "没有数据");
                }
            } else {
                objectMap.put("total", workService.countLimitNum(schoolwork2));
                objectMap.put("code", 201);
                objectMap.put("message", "没有数据");
            }
        } else {
            objectMap.put("code", 203);
            objectMap.put("message", "此用户没有权限做此操作");
        }
        return objectMap;
    }


    /**
     * 添加发布作业
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/add")
    public synchronized
    @ResponseBody
    Object
    teacherAddWork(HttpServletRequest request
    ) {// , @RequestParam(value = "file", required = false) MultipartFile file
        Map<String, Object> map = new HashMap<String, Object>();
        String teacherid = request.getParameter("teacherId");
        String courseskuid = request.getParameter("courseId");
        String schoolworkcontent = request.getParameter("schoolWorkContent");
        Date date = new Date();
        SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String releasetime = time.format(date);
        String handovertime = request.getParameter("handOverTime");
        String studentid = request.getParameter("student");
        String workname = request.getParameter("workName");
        String token = request.getParameter("token");
        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(teacherid, token);
        String schoolworkUrl;
        schoolworkUrl = "";
        if (teacherData != null) {
            String path = request.getSession().getServletContext().getRealPath("/") + "upload";
//            String fileName = file.getOriginalFilename();
//            File targetFile;
//            if (fileName.equals("")) {
//            } else {
//                String key = teacherid + "-work-" + fileName;
//                targetFile = new File(path, key);
//                if (!targetFile.exists()) {
//                    targetFile.mkdirs();
//                    try {
//                        file.transferTo(targetFile);
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                } else {
//                    targetFile.delete();
//                    try {
//                        file.transferTo(targetFile);
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                }
//                schoolworkUrl = AliyunOssUtil.save(key, targetFile.getPath());
//                targetFile.delete();
//            }

            Schoolwork schoolwork = new Schoolwork(teacherid, courseskuid, schoolworkcontent, handovertime
                    , releasetime, workname, schoolworkUrl);
            if (workService.selectByAll(schoolwork) == null) {
                if (workService.insertSelective(schoolwork) > 0) {
                    JSONArray jsonArray = JSONArray.fromObject(studentid);
                    JSONObject jsonObject;
                    for (int i = 0; i < jsonArray.size(); i++) {
                        jsonObject = jsonArray.getJSONObject(i);
                        studentid = jsonObject.getString("studentId");
                        StudentWork studentWork = new StudentWork(studentid, workService.selectByAll(schoolwork).getSchoolworkid(), "未阅读");
                        workService.insertSelective(studentWork);
                    }
                    map.put("code", 200);
                    map.put("message", "成功");
                } else {
                    map.put("code", 201);
                    map.put("message", "失败");
                }
            } else {
                map.put("code", 202);
                map.put("message", "请勿添加重复项");
            }
        } else {
            map.put("code", 203);
            map.put("message", "此用户没有权限做此操作");
        }
        return map;
    }

    /**
     * 查看课程名和id
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/course")
    public synchronized
    @ResponseBody
    Object
    courseWork(HttpServletRequest request) {
        Map<String, Object> objectMap = new HashMap<String, Object>();
        List<Map> mapList = new ArrayList<Map>();
        Map<String, Object> map;
        String teacherId = request.getParameter("teacherId");
        String token = request.getParameter("token");
        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(teacherId, token);
        if (teacherData != null) {
            List<Course> course = courseService.selectByTeacher(teacherId);
            if (course != null) {
                for (int i = 0; i < course.size(); i++) {
                    map = new HashMap<String, Object>();
                    map.put("courseId", course.get(i).getCourseid());
                    map.put("courseName", course.get(i).getCoursename());
                    map.put("courseTime", course.get(i).getCoursetime());
                    map.put("courseClass", course.get(i).getCourseclasss());
                    mapList.add(map);
                }
            }
            if (mapList != null && mapList.size() > 0) {
                objectMap.put("message", "成功");
                objectMap.put("code", 200);
                objectMap.put("data", mapList);
            } else {
                objectMap.put("message", "当前老师没有课程");
                objectMap.put("code", 201);
            }
        } else {
            objectMap.put("code", 203);
            objectMap.put("message", "此用户没有权限做此操作");
        }
        return objectMap;
    }

    /**
     * 查看学生和分组信息
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/student")
    public synchronized
    @ResponseBody
    Object studentWork(HttpServletRequest request) {
        Map<String, Object> objectMap = new HashMap<String, Object>();
        List<Map> mapList = new ArrayList<Map>();
        Map<String, Object> map;
        Map<String, Object> map3;
        Map<String, Object> map4 = new HashMap<String, Object>();
        String czid = request.getParameter("courseId");
        String cteacherid = request.getParameter("teacherId");
        String classname = request.getParameter("className");
        String token = request.getParameter("token");
        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(cteacherid, token);
        if (teacherData != null) {
            String cteacher = teacherData.getTeachername();
            Course classs;
            List<Student> student;
            StudentGrouping studentGrouping;
            int n = 1;
            StudentApp studentApp;
            System.out.println(classname);
            if (classname.equals("")) {
                Course course = new Course(czid, cteacher);
                classs = courseService.selectClass(course);
                if (classs != null) {
                    if (splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n).length > 0) {
                        List<Map> mapList2 = new ArrayList<Map>();
                        Grouping grouping = new Grouping();
                        grouping.setTeacherid(cteacherid);
                        grouping.setCourseid(czid);
                        List<Grouping> groupingList = studentGroupingService.selectByTeaIdCouId(grouping);
                        if (groupingList != null && groupingList.size() > 0) {
                            for (int i = 0; i < groupingList.size(); i++) {
                                map3 = new HashMap<String, Object>();
                                String groupName = groupingList.get(i).getGroupname();
                                int groupId = groupingList.get(i).getGroupnameid();
                                String num1 = groupName;
                                List<Map> mapList1 = new ArrayList<Map>();
                                for (int i1 = 0; i1 < splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n).length; i1++) {
                                    student = studentService.selectByClass(splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                    if (student != null) {
                                        for (int i2 = 0; i2 < student.size(); i2++) {
                                            map = new HashMap<String, Object>();
                                            map.put("class", splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                            map.put("studentId", student.get(i2).getStudentid());
                                            map.put("studentName", student.get(i2).getStudentname());
                                            studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                                            map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                                            studentGrouping = new StudentGrouping();
                                            studentGrouping.setTeacherid(cteacherid);
                                            studentGrouping.setCourseid(czid);
                                            studentGrouping.setStuid(student.get(i2).getStudentid());
                                            studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                            if (studentGrouping != null) {
                                                if (studentGrouping.getGroupname() == groupId) {
                                                    map.put("groupId", studentGrouping.getGroupid() + "");
                                                    map.put("groupingId", studentGrouping.getGroupname());
                                                    mapList1.add(map);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (mapList1 != null) {
                                    map3.put("num", mapList1.size());
                                    map3.put("groupingId", groupId);
                                    map3.put("group", mapList1);
                                    map3.put("groupingName", num1);
                                } else {
                                    map3.put("num", 0);
                                    map3.put("groupingId", groupId);
                                    map3.put("group", mapList1);
                                    map3.put("groupingName", num1);
                                }
                                mapList.add(map3);
                            }
                            for (int i1 = 0; i1 < splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n).length; i1++) {
                                student = studentService.selectByClass(splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                if (student != null) {
                                    for (int i2 = 0; i2 < student.size(); i2++) {
                                        map = new HashMap<String, Object>();
                                        map.put("class", splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                        map.put("studentId", student.get(i2).getStudentid());
                                        map.put("studentName", student.get(i2).getStudentname());
                                        studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                                        map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                                        studentGrouping = new StudentGrouping();
                                        studentGrouping.setTeacherid(cteacherid);
                                        studentGrouping.setCourseid(czid);
                                        studentGrouping.setStuid(student.get(i2).getStudentid());
                                        studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                        if (studentGrouping != null) {
                                            if (studentGrouping.getGroupname() == 0) {
                                                map.put("groupId", studentGrouping.getGroupid() + "");
                                                map.put("groupingId", studentGrouping.getGroupname());
                                                mapList2.add(map);
                                            }
                                        } else {
                                            studentGrouping = new StudentGrouping(cteacherid, student.get(i2).getStudentid(), splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]
                                                    , course.getCourseid(), 0);
                                            studentGroupingService.insertSelective(studentGrouping);
                                            map.put("groupingId", 0 + "");
                                            studentGrouping = new StudentGrouping();
                                            studentGrouping.setTeacherid(cteacherid);
                                            studentGrouping.setCourseid(czid);
                                            studentGrouping.setStuid(student.get(i2).getStudentid());
                                            studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                            map.put("groupId", studentGrouping.getGroupid() + "");
                                            mapList2.add(map);
                                        }
                                    }
                                }
                            }
                            if (mapList2 != null) {
                                map4.put("num", mapList2.size());
                                map4.put("groupingId", 0);
                                map4.put("group", mapList2);
                                map4.put("groupingName", "未分组");
                            } else {
                                map4.put("num", 0);
                                map4.put("groupingId", 0);
                                map4.put("group", mapList2);
                                map4.put("groupingName", "未分组");
                            }
                            mapList.add(map4);
                        } else {
                            map3 = new HashMap<String, Object>();
                            for (int i1 = 0; i1 < splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n).length; i1++) {
                                student = studentService.selectByClass(splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                if (student != null) {
                                    for (int i2 = 0; i2 < student.size(); i2++) {
                                        map = new HashMap<String, Object>();
                                        map.put("class", splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]);
                                        map.put("studentId", student.get(i2).getStudentid());
                                        map.put("studentName", student.get(i2).getStudentname());
                                        studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                                        map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                                        studentGrouping = new StudentGrouping();
                                        studentGrouping.setTeacherid(cteacherid);
                                        studentGrouping.setCourseid(czid);
                                        studentGrouping.setStuid(student.get(i2).getStudentid());
                                        studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                        if (studentGrouping != null) {
                                            int id = studentGrouping.getGroupid();
                                            map.put("groupId", id + "");
                                            studentGrouping = new StudentGrouping();
                                            studentGrouping.setGroupname(0);
                                            studentGrouping.setGroupid(id);
                                            studentGroupingService.updateByPrimaryKeySelective(studentGrouping);
                                            map.put("groupingId", 0 + "");
                                            mapList2.add(map);
                                        } else {
                                            studentGrouping = new StudentGrouping(cteacherid, student.get(i2).getStudentid(), splitSpring.splitSpringBy(classs.getCourseclasss(), 0, 0, ",", n)[i1]
                                                    , course.getCourseid(), 0);
                                            studentGroupingService.insertSelective(studentGrouping);
                                            map.put("groupingId", 0 + "");
                                            studentGrouping = new StudentGrouping();
                                            studentGrouping.setTeacherid(cteacherid);
                                            studentGrouping.setCourseid(czid);
                                            studentGrouping.setStuid(student.get(i2).getStudentid());
                                            studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                            map.put("groupId", studentGrouping.getGroupid() + "");
                                            mapList2.add(map);
                                        }
                                    }
                                }
                            }
                            if (mapList2 != null) {
                                map3.put("num", mapList2.size());
                                map3.put("group", mapList2);
                                map3.put("groupingId", 0 + "");
                                map3.put("groupingName", "未分组");
                            } else {
                                map3.put("num", 0);
                                map3.put("group", mapList2);
                                map3.put("groupingId", 0 + "");
                                map3.put("groupingName", "未分组");
                            }
                            mapList.add(map3);
                        }
                    }
                }
            } else {
                List<Map> mapList2 = new ArrayList<Map>();
                Grouping grouping = new Grouping();
                grouping.setTeacherid(cteacherid);
                grouping.setCourseid(czid);
                List<Grouping> groupingList = studentGroupingService.selectByTeaIdCouId(grouping);
                if (groupingList != null && groupingList.size() > 0) {
                    for (int i = 0; i < groupingList.size(); i++) {
                        map3 = new HashMap<String, Object>();
                        String groupName = groupingList.get(i).getGroupname();
                        int groupId = groupingList.get(i).getGroupnameid();
                        List<Map> mapList1 = new ArrayList<Map>();
                        String num1 = groupName;
                        student = studentService.selectByClass(classname);
                        if (student != null) {
                            for (int i2 = 0; i2 < student.size(); i2++) {
                                map = new HashMap<String, Object>();
                                map.put("class", classname);
                                map.put("studentId", student.get(i2).getStudentid());
                                map.put("studentName", student.get(i2).getStudentname());
                                studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                                map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                                studentGrouping = new StudentGrouping();
                                studentGrouping.setTeacherid(cteacherid);
                                studentGrouping.setCourseid(czid);
                                studentGrouping.setStuid(student.get(i2).getStudentid());
                                studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                if (studentGrouping != null) {
                                    if (studentGrouping.getGroupname() == groupId) {
                                        num1 = groupName;
                                        map.put("groupId", studentGrouping.getGroupid() + "");
                                        map.put("groupingId", studentGrouping.getGroupname());
                                        mapList1.add(map);
                                    }
                                }
                            }
                        }
                        if (mapList1 != null) {
                            map3.put("num", mapList1.size());
                            map3.put("groupingId", groupId);
                            map3.put("group", mapList1);
                            map3.put("groupingName", num1);
                        } else {
                            map3.put("num", 0);
                            map3.put("groupingId", groupId);
                            map3.put("group", mapList1);
                            map3.put("groupingName", num1);
                        }
                        mapList.add(map3);
                    }
                    student = studentService.selectByClass(classname);
                    if (student != null) {
                        for (int i2 = 0; i2 < student.size(); i2++) {
                            map = new HashMap<String, Object>();
                            map.put("class", classname);
                            map.put("studentId", student.get(i2).getStudentid());
                            map.put("studentName", student.get(i2).getStudentname());
                            studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                            map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                            studentGrouping = new StudentGrouping();
                            studentGrouping.setTeacherid(cteacherid);
                            studentGrouping.setCourseid(czid);
                            studentGrouping.setStuid(student.get(i2).getStudentid());
                            studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                            if (studentGrouping != null) {
                                if (studentGrouping.getGroupname() == 0) {
                                    map.put("groupId", studentGrouping.getGroupid() + "");
                                    map.put("groupingId", studentGrouping.getGroupname());
                                    mapList2.add(map);
                                }
                            } else {
                                studentGrouping = new StudentGrouping(cteacherid, student.get(i2).getStudentid(), classname
                                        , czid, 0);
                                studentGroupingService.insertSelective(studentGrouping);
                                map.put("groupingId", 0 + "");
                                studentGrouping = new StudentGrouping();
                                studentGrouping.setTeacherid(cteacherid);
                                studentGrouping.setCourseid(czid);
                                studentGrouping.setStuid(student.get(i2).getStudentid());
                                studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                map.put("groupId", studentGrouping.getGroupid() + "");
                                mapList2.add(map);
                            }
                        }
                    }
                    if (mapList2 != null) {
                        map4.put("num", mapList2.size());
                        map4.put("groupingId", 0);
                        map4.put("group", mapList2);
                        map4.put("groupingName", "未分组");
                    } else {
                        map4.put("num", 0);
                        map4.put("groupingId", 0);
                        map4.put("group", mapList2);
                        map4.put("groupingName", "未分组");
                    }
                    mapList.add(map4);
                } else {
                    map3 = new HashMap<String, Object>();
                    student = studentService.selectByClass(classname);
                    if (student != null) {
                        for (int i2 = 0; i2 < student.size(); i2++) {
                            map = new HashMap<String, Object>();
                            map.put("class", classname);
                            map.put("studentId", student.get(i2).getStudentid());
                            map.put("studentName", student.get(i2).getStudentname());
                            studentApp = studentAppService.selectByPrimaryKey(student.get(i2).getStudentid());
                            map.put("studentHeadPortrait", studentApp.getStudentheadportrait());
                            studentGrouping = new StudentGrouping();
                            studentGrouping.setTeacherid(cteacherid);
                            studentGrouping.setCourseid(czid);
                            studentGrouping.setStuid(student.get(i2).getStudentid());
                            studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                            if (studentGrouping != null) {
                                int id = studentGrouping.getGroupid();
                                map.put("groupId", id + "");
                                studentGrouping = new StudentGrouping();
                                studentGrouping.setGroupname(0);
                                studentGrouping.setGroupid(id);
                                studentGroupingService.updateByPrimaryKeySelective(studentGrouping);
                                map.put("groupingName", "未分组");
                                mapList2.add(map);
                            } else {
                                studentGrouping = new StudentGrouping(cteacherid, student.get(i2).getStudentid(), classname
                                        , czid, 0);
                                studentGroupingService.insertSelective(studentGrouping);
                                map.put("groupingId", 0 + "");
                                studentGrouping = new StudentGrouping();
                                studentGrouping.setTeacherid(cteacherid);
                                studentGrouping.setCourseid(czid);
                                studentGrouping.setStuid(student.get(i2).getStudentid());
                                studentGrouping = studentGroupingService.selectByStuIdCouID(studentGrouping);
                                map.put("groupId", studentGrouping.getGroupid() + "");
                                mapList2.add(map);
                            }
                        }
                    }
                    if (mapList2 != null) {
                        map3.put("num", mapList2.size());
                        map3.put("group", mapList2);
                        map3.put("groupingId", 0 + "");
                        map3.put("groupingName", "未分组");
                    } else {
                        map3.put("num", 0);
                        map3.put("group", mapList2);
                        map3.put("groupingId", 0 + "");
                        map3.put("groupingName", "未分组");
                    }
                    mapList.add(map3);
                }
            }
            if (mapList != null) {
                objectMap.put("data", mapList);
                objectMap.put("code", 200);
                objectMap.put("message", "成功");
            } else {
                objectMap.put("code", 201);
                objectMap.put("message", "没有获取到");
            }
        } else {
            objectMap.put("code", 203);
            objectMap.put("message", "此用户没有权限做此操作");
        }
        return objectMap;
    }

    @RequestMapping(value = "/delWork")
    public synchronized
    @ResponseBody
    Object
    delWork(HttpServletRequest request) {
        Map<String, Object> objectMap = new HashMap<String, Object>();
        String teacherId = request.getParameter("teacherId");
        String token = request.getParameter("token");
        Integer schoolWorkId = Integer.parseInt(request.getParameter("schoolWorkId"));
        TeacherData teacherData;
        teacherData = (TeacherData) tokenController.token(teacherId, token);
        if (teacherData != null) {
            if (workService.deleteByPrimaryKey(schoolWorkId)>0){
                StudentWork studentWork = new StudentWork();
                studentWork.setWorkid(schoolWorkId);
                workService.deleteBySchoolWork(studentWork);
                objectMap.put("code", 200);
                objectMap.put("message", "成功");
            }else {
                objectMap.put("code", 201);
                objectMap.put("message", "删除失败");
            }
        } else {
            objectMap.put("code", 203);
            objectMap.put("message", "此用户没有权限做此操作");
        }
        return objectMap;
    }
}
